import xlrd,xlwt,openpyxl,requests


def read_excel(path):
    workbook = xlrd.open_workbook(path)
    print(workbook.sheet_names())

    sheet1 = workbook.sheet_by_index(0)

    print(sheet1.name, sheet1.nrows, sheet1.ncols)

    print(sheet1.cell(1, 0).value)
    print(sheet1.cell(1, 1).value)
    print(sheet1.cell(1, 2).value)


def write_excel():
    workbook = xlwt.Workbook(encoding="utf-8")


def read_excel2(path,ignore):
    workbook = openpyxl.load_workbook(path)
    table = workbook.worksheets[0]
    rows = table.max_row
    clons = table.max_column
    for i in range(ignore + 1, rows + 1):
        for j in range(1, clons + 1):
            pass

def read_excel3(path,ignore):
    workbook = openpyxl.load_workbook(path)
    table = workbook.worksheets[0]
    rows = table.max_row
    clons = table.max_column
    for i in range(ignore + 1, rows + 1):
        for j in range(1, clons + 1):
            yield table.cell(i, j).value,i

def read_excel_for_idx(path,coldexs,brow = '',erow = ''):
    workbook = openpyxl.load_workbook(path)
    table = workbook.worksheets[0]
    if brow == '' : brow = 1
    if erow == '' : erow = table.max_row

    for i in range(brow+1 , erow+1):
        for j in coldexs:
            yield table.cell(i,j).value,i

def del_rows(path,rowdexs):
    workbook = openpyxl.load_workbook(path)
    table = workbook.worksheets[0]

    for i in rowdexs:
        table.delete_rows(i)

if __name__ == '__main__':

    #read_excel2(r'./iptv.xlsx',1)
    itera = read_excel3(r'./iptv.xlsx',1)
    for i in itera:
        pass
    print('end')
    #校验iptv表格的源
    '''
    sources = read_excel_for_idx(r'./iptv.xlsx',[2])
    del_list = []
    for i in sources:
        if requests.get(i[0]).status_code != 200:
            del_list.append(i[1])

    print(del_list)
    '''